home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Headers / Universal Headers 2.0.1f / MIDI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-22  |  11.5 KB  |  316 lines  |  [TEXT/MMCC]

  1. /*
  2.      File:        MIDI.h
  3.  
  4.      Contains:    MIDI Manager Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Package:    Universal Interfaces 2.0 in “MPW Latest” on ETO #17
  8.  
  9.      Copyright:    © 1984-1995 by Apple Computer, Inc.
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, use the Apple Bug Reporter
  13.                  stack.  Include the file and version information (from above)
  14.                  in the problem description and send to:
  15.                      Internet:    apple.bugs@applelink.apple.com
  16.                      AppleLink:    APPLE.BUGS
  17.  
  18. */
  19.  
  20. #ifndef __MIDI__
  21. #define __MIDI__
  22.  
  23.  
  24. #ifndef __ERRORS__
  25. #include <Errors.h>
  26. #endif
  27. /*    #include <ConditionalMacros.h>                                */
  28.  
  29. #ifndef __TYPES__
  30. #include <Types.h>
  31. #endif
  32.  
  33. #ifndef __MIXEDMODE__
  34. #include <MixedMode.h>
  35. #endif
  36.  
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40.  
  41. #if PRAGMA_ALIGN_SUPPORTED
  42. #pragma options align=mac68k
  43. #endif
  44.  
  45. #if PRAGMA_IMPORT_SUPPORTED
  46. #pragma import on
  47. #endif
  48.  
  49.  
  50. enum {
  51.     midiToolNum                    = 4,                            /*tool number of MIDI Manager for SndDispVersion call*/
  52.     midiMaxNameLen                = 31,                            /*maximum number of characters in port and client names*/
  53. /* Time formats */
  54.     midiFormatMSec                = 0,                            /*milliseconds*/
  55.     midiFormatBeats                = 1,                            /*beats*/
  56.     midiFormat24fpsBit            = 2,                            /*24 frames/sec.*/
  57.     midiFormat25fpsBit            = 3,                            /*25 frames/sec.*/
  58.     midiFormat30fpsDBit            = 4,                            /*30 frames/sec. drop-frame*/
  59.     midiFormat30fpsBit            = 5,                            /*30 frames/sec.*/
  60.     midiFormat24fpsQF            = 6,                            /*24 frames/sec. longInt format */
  61.     midiFormat25fpsQF            = 7,                            /*25 frames/sec. longInt format */
  62.     midiFormat30fpsDQF            = 8,                            /*30 frames/sec. drop-frame longInt format */
  63.     midiFormat30fpsQF            = 9,                            /*30 frames/sec. longInt format */
  64.     midiInternalSync            = 0,                            /*internal sync*/
  65.     midiExternalSync            = 1,                            /*external sync*/
  66. /* Port types*/
  67.     midiPortTypeTime            = 0,                            /*time port*/
  68.     midiPortTypeInput            = 1,                            /*input port*/
  69.     midiPortTypeOutput            = 2,                            /*output port*/
  70.     midiPortTypeTimeInv            = 3,                            /*invisible time port*/
  71. /* OffsetTimes  */
  72.     midiGetEverything            = 0x7FFFFFFF,                    /*get all packets, regardless of time stamps*/
  73.     midiGetNothing                = 0x80000000L,                    /*get no packets, regardless of time stamps*/
  74.     midiGetCurrent                = 0x00000000                    /*get current packets only*/
  75. };
  76.  
  77. /*    MIDI data and messages are passed in MIDIPacket records (see below).
  78.     The first byte of every MIDIPacket contains a set of flags
  79.  
  80.     bits 0-1    00 = new MIDIPacket, not continued
  81.                      01 = begining of continued MIDIPacket
  82.                      10 = end of continued MIDIPacket
  83.                      11 = continuation
  84.     bits 2-3     reserved
  85.  
  86.     bits 4-6      000 = packet contains MIDI data
  87.  
  88.                   001 = packet contains MIDI Manager message
  89.  
  90.     bit 7         0 = MIDIPacket has valid stamp
  91.                   1 = stamp with current clock
  92. */
  93. enum {
  94.     midiContMask                = 0x03,
  95.     midiNoCont                    = 0x00,
  96.     midiStartCont                = 0x01,
  97.     midiMidCont                    = 0x03,
  98.     midiEndCont                    = 0x02,
  99.     midiTypeMask                = 0x70,
  100.     midiMsgType                    = 0x00,
  101.     midiMgrType                    = 0x10,
  102.     midiTimeStampMask            = 0x80,
  103.     midiTimeStampCurrent        = 0x80,
  104.     midiTimeStampValid            = 0x00,
  105. /* MIDIPacket command words (the first word in the data field for midiMgrType messages) */
  106.     midiOverflowErr                = 0x0001,
  107.     midiSCCErr                    = 0x0002,
  108.     midiPacketErr                = 0x0003,
  109. /*all command words less than this value are error indicators*/
  110.     midiMaxErr                    = 0x00FF,
  111. /* Valid results to be returned by readHooks */
  112.     midiKeepPacket                = 0,
  113.     midiMorePacket                = 1,
  114.     midiNoMorePacket            = 2,
  115. /* Driver calls */
  116.     midiOpenDriver                = 1,
  117.     midiCloseDriver                = 2
  118. };
  119.  
  120. struct MIDIPacket {
  121.     UInt8                            flags;
  122.     UInt8                            len;
  123.     long                            tStamp;
  124.     UInt8                            data[249];
  125. };
  126. typedef struct MIDIPacket MIDIPacket;
  127.  
  128. typedef MIDIPacket *MIDIPacketPtr;
  129.  
  130. typedef pascal short (*MIDIReadHookProcPtr)(MIDIPacketPtr myPacket, long myRefCon);
  131. typedef pascal void (*MIDITimeProcPtr)(long curTime, long myRefCon);
  132.  
  133. #if GENERATINGCFM
  134. typedef UniversalProcPtr MIDIReadHookUPP;
  135. typedef UniversalProcPtr MIDITimeUPP;
  136. #else
  137. typedef MIDIReadHookProcPtr MIDIReadHookUPP;
  138. typedef MIDITimeProcPtr MIDITimeUPP;
  139. #endif
  140.  
  141. struct MIDIClkInfo {
  142.     short                            syncType;                    /*synchronization external/internal*/
  143.     long                            curTime;                    /*current value of port's clock*/
  144.     short                            format;                        /*time code format*/
  145. };
  146. typedef struct MIDIClkInfo MIDIClkInfo;
  147.  
  148. struct MIDIIDRec {
  149.     OSType                            clientID;
  150.     OSType                            portID;
  151. };
  152. typedef struct MIDIIDRec MIDIIDRec;
  153.  
  154. struct MIDIPortInfo {
  155.     short                            portType;                    /*type of port*/
  156.     MIDIIDRec                        timeBase;                    /*MIDIIDRec for time base*/
  157.     short                            numConnects;                /*number of connections*/
  158.     MIDIIDRec                        cList[1];                    /*ARRAY [1..numConnects] of MIDIIDRec*/
  159. };
  160. typedef struct MIDIPortInfo MIDIPortInfo;
  161.  
  162. typedef MIDIPortInfo *MIDIPortInfoPtr, **MIDIPortInfoHdl, **MIDIPortInfoHandle;
  163.  
  164. struct MIDIPortParams {
  165.     OSType                            portID;                        /*ID of port, unique within client*/
  166.     short                            portType;                    /*Type of port - input, output, time, etc.*/
  167.     short                            timeBase;                    /*refnum of time base, 0 if none*/
  168.     long                            offsetTime;                    /*offset for current time stamps*/
  169.     MIDIReadHookUPP                    readHook;                    /*routine to call when input data is valid*/
  170.     long                            refCon;                        /*refcon for port (for client use)*/
  171.     MIDIClkInfo                        initClock;                    /*initial settings for a time base*/
  172.     Str255                            name;                        /*name of the port, This is a real live string, not a ptr.*/
  173. };
  174. typedef struct MIDIPortParams MIDIPortParams;
  175.  
  176. typedef MIDIPortParams *MIDIPortParamsPtr;
  177.  
  178. struct MIDIIDList {
  179.     short                            numIDs;
  180.     OSType                            list[1];
  181. };
  182. typedef struct MIDIIDList MIDIIDList;
  183.  
  184. typedef MIDIIDList *MIDIIDListPtr, **MIDIIDListHdl, **MIDIIDListHandle;
  185.  
  186. extern pascal NumVersion MIDIVersion(void)
  187.  FOURWORDINLINE(0x203C, 0x0000, 4, 0xA800);
  188. extern pascal OSErr MIDISignIn(OSType clientID, long refCon, Handle icon, ConstStr255Param name)
  189.  FOURWORDINLINE(0x203C, 0x0004, 4, 0xA800);
  190. extern pascal void MIDISignOut(OSType clientID)
  191.  FOURWORDINLINE(0x203C, 0x0008, 4, 0xA800);
  192. extern pascal MIDIIDListHandle MIDIGetClients(void)
  193.  FOURWORDINLINE(0x203C, 0x000C, 4, 0xA800);
  194. extern pascal void MIDIGetClientName(OSType clientID, Str255 name)
  195.  FOURWORDINLINE(0x203C, 0x0010, 4, 0xA800);
  196. extern pascal void MIDISetClientName(OSType clientID, ConstStr255Param name)
  197.  FOURWORDINLINE(0x203C, 0x0014, 4, 0xA800);
  198. extern pascal MIDIIDListHandle MIDIGetPorts(OSType clientID)
  199.  FOURWORDINLINE(0x203C, 0x0018, 4, 0xA800);
  200. extern pascal OSErr MIDIAddPort(OSType clientID, short BufSize, short *refnum, MIDIPortParamsPtr init)
  201.  FOURWORDINLINE(0x203C, 0x001C, 4, 0xA800);
  202. extern pascal MIDIPortInfoHandle MIDIGetPortInfo(OSType clientID, OSType portID)
  203.  FOURWORDINLINE(0x203C, 0x0020, 4, 0xA800);
  204. extern pascal OSErr MIDIConnectData(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  205.  FOURWORDINLINE(0x203C, 0x0024, 4, 0xA800);
  206. extern pascal OSErr MIDIUnConnectData(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  207.  FOURWORDINLINE(0x203C, 0x0028, 4, 0xA800);
  208. extern pascal OSErr MIDIConnectTime(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  209.  FOURWORDINLINE(0x203C, 0x002C, 4, 0xA800);
  210. extern pascal OSErr MIDIUnConnectTime(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  211.  FOURWORDINLINE(0x203C, 0x0030, 4, 0xA800);
  212. extern pascal void MIDIFlush(short refnum)
  213.  FOURWORDINLINE(0x203C, 0x0034, 4, 0xA800);
  214. extern pascal ProcPtr MIDIGetReadHook(short refnum)
  215.  FOURWORDINLINE(0x203C, 0x0038, 4, 0xA800);
  216. extern pascal void MIDISetReadHook(short refnum, ProcPtr hook)
  217.  FOURWORDINLINE(0x203C, 0x003C, 4, 0xA800);
  218. extern pascal void MIDIGetPortName(OSType clientID, OSType portID, Str255 name)
  219.  FOURWORDINLINE(0x203C, 0x0040, 4, 0xA800);
  220. extern pascal void MIDISetPortName(OSType clientID, OSType portID, ConstStr255Param name)
  221.  FOURWORDINLINE(0x203C, 0x0044, 4, 0xA800);
  222. extern pascal void MIDIWakeUp(short refnum, long time, long period, MIDITimeUPP timeProc)
  223.  FOURWORDINLINE(0x203C, 0x0048, 4, 0xA800);
  224. extern pascal void MIDIRemovePort(short refnum)
  225.  FOURWORDINLINE(0x203C, 0x004C, 4, 0xA800);
  226. extern pascal short MIDIGetSync(short refnum)
  227.  FOURWORDINLINE(0x203C, 0x0050, 4, 0xA800);
  228. extern pascal void MIDISetSync(short refnum, short sync)
  229.  FOURWORDINLINE(0x203C, 0x0054, 4, 0xA800);
  230. extern pascal long MIDIGetCurTime(short refnum)
  231.  FOURWORDINLINE(0x203C, 0x0058, 4, 0xA800);
  232. extern pascal void MIDISetCurTime(short refnum, long time)
  233.  FOURWORDINLINE(0x203C, 0x005C, 4, 0xA800);
  234. extern pascal void MIDIStartTime(short refnum)
  235.  FOURWORDINLINE(0x203C, 0x0060, 4, 0xA800);
  236. extern pascal void MIDIStopTime(short refnum)
  237.  FOURWORDINLINE(0x203C, 0x0064, 4, 0xA800);
  238. extern pascal void MIDIPoll(short refnum, long offsetTime)
  239.  FOURWORDINLINE(0x203C, 0x0068, 4, 0xA800);
  240. extern pascal OSErr MIDIWritePacket(short refnum, MIDIPacketPtr packet)
  241.  FOURWORDINLINE(0x203C, 0x006C, 4, 0xA800);
  242. extern pascal Boolean MIDIWorldChanged(OSType clientID)
  243.  FOURWORDINLINE(0x203C, 0x0070, 4, 0xA800);
  244. extern pascal long MIDIGetOffsetTime(short refnum)
  245.  FOURWORDINLINE(0x203C, 0x0074, 4, 0xA800);
  246. extern pascal void MIDISetOffsetTime(short refnum, long offsetTime)
  247.  FOURWORDINLINE(0x203C, 0x0078, 4, 0xA800);
  248. extern pascal long MIDIConvertTime(short srcFormat, short dstFormat, long time)
  249.  FOURWORDINLINE(0x203C, 0x007C, 4, 0xA800);
  250. extern pascal long MIDIGetRefCon(short refnum)
  251.  FOURWORDINLINE(0x203C, 0x0080, 4, 0xA800);
  252. extern pascal void MIDISetRefCon(short refnum, long refCon)
  253.  FOURWORDINLINE(0x203C, 0x0084, 4, 0xA800);
  254. extern pascal long MIDIGetClRefCon(OSType clientID)
  255.  FOURWORDINLINE(0x203C, 0x0088, 4, 0xA800);
  256. extern pascal void MIDISetClRefCon(OSType clientID, long refCon)
  257.  FOURWORDINLINE(0x203C, 0x008C, 4, 0xA800);
  258. extern pascal short MIDIGetTCFormat(short refnum)
  259.  FOURWORDINLINE(0x203C, 0x0090, 4, 0xA800);
  260. extern pascal void MIDISetTCFormat(short refnum, short format)
  261.  FOURWORDINLINE(0x203C, 0x0094, 4, 0xA800);
  262. extern pascal void MIDISetRunRate(short refnum, short rate, long time)
  263.  FOURWORDINLINE(0x203C, 0x0098, 4, 0xA800);
  264. extern pascal Handle MIDIGetClientIcon(OSType clientID)
  265.  FOURWORDINLINE(0x203C, 0x009C, 4, 0xA800);
  266. extern pascal long SndDispVersion(short toolnum)
  267.  FOURWORDINLINE(0x203C, 0x0000, 0x0000, 0xA800);
  268. enum {
  269.     uppMIDIReadHookProcInfo = kPascalStackBased
  270.          | RESULT_SIZE(SIZE_CODE(sizeof(short)))
  271.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(MIDIPacketPtr)))
  272.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))),
  273.     uppMIDITimeProcInfo = kPascalStackBased
  274.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
  275.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long)))
  276. };
  277.  
  278. #if GENERATINGCFM
  279. #define NewMIDIReadHookProc(userRoutine)        \
  280.         (MIDIReadHookUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppMIDIReadHookProcInfo, GetCurrentArchitecture())
  281. #define NewMIDITimeProc(userRoutine)        \
  282.         (MIDITimeUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), uppMIDITimeProcInfo, GetCurrentArchitecture())
  283. #else
  284. #define NewMIDIReadHookProc(userRoutine)        \
  285.         ((MIDIReadHookUPP) (userRoutine))
  286. #define NewMIDITimeProc(userRoutine)        \
  287.         ((MIDITimeUPP) (userRoutine))
  288. #endif
  289.  
  290. #if GENERATINGCFM
  291. #define CallMIDIReadHookProc(userRoutine, myPacket, myRefCon)        \
  292.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppMIDIReadHookProcInfo, (myPacket), (myRefCon))
  293. #define CallMIDITimeProc(userRoutine, curTime, myRefCon)        \
  294.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppMIDITimeProcInfo, (curTime), (myRefCon))
  295. #else
  296. #define CallMIDIReadHookProc(userRoutine, myPacket, myRefCon)        \
  297.         (*(userRoutine))((myPacket), (myRefCon))
  298. #define CallMIDITimeProc(userRoutine, curTime, myRefCon)        \
  299.         (*(userRoutine))((curTime), (myRefCon))
  300. #endif
  301.  
  302.  
  303. #if PRAGMA_IMPORT_SUPPORTED
  304. #pragma import off
  305. #endif
  306.  
  307. #if PRAGMA_ALIGN_SUPPORTED
  308. #pragma options align=reset
  309. #endif
  310.  
  311. #ifdef __cplusplus
  312. }
  313. #endif
  314.  
  315. #endif /* __MIDI__ */
  316.